home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_gawk.idb / usr / freeware / share / awk / passwd.awk.z / passwd.awk
Text File  |  2002-07-08  |  1KB  |  64 lines

  1. # passwd.awk --- access password file information
  2. #
  3. # Arnold Robbins, arnold@gnu.org, Public Domain
  4. # May 1993
  5. # Revised October 2000
  6.  
  7. BEGIN {
  8.     # tailor this to suit your system
  9.     _pw_awklib = "/usr/freeware/libexec/awk/"
  10. }
  11.  
  12. function _pw_init(    oldfs, oldrs, olddol0, pwcat, using_fw)
  13. {
  14.     if (_pw_inited)
  15.         return
  16.  
  17.     oldfs = FS
  18.     oldrs = RS
  19.     olddol0 = $0
  20.     using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")
  21.     FS = ":"
  22.     RS = "\n"
  23.  
  24.     pwcat = _pw_awklib "pwcat"
  25.     while ((pwcat | getline) > 0) {
  26.         _pw_byname[$1] = $0
  27.         _pw_byuid[$3] = $0
  28.         _pw_bycount[++_pw_total] = $0
  29.     }
  30.     close(pwcat)
  31.     _pw_count = 0
  32.     _pw_inited = 1
  33.     FS = oldfs
  34.     if (using_fw)
  35.         FIELDWIDTHS = FIELDWIDTHS
  36.     RS = oldrs
  37.     $0 = olddol0
  38. }
  39. function getpwnam(name)
  40. {
  41.     _pw_init()
  42.     if (name in _pw_byname)
  43.         return _pw_byname[name]
  44.     return ""
  45. }
  46. function getpwuid(uid)
  47. {
  48.     _pw_init()
  49.     if (uid in _pw_byuid)
  50.         return _pw_byuid[uid]
  51.     return ""
  52. }
  53. function getpwent()
  54. {
  55.     _pw_init()
  56.     if (_pw_count < _pw_total)
  57.         return _pw_bycount[++_pw_count]
  58.     return ""
  59. }
  60. function endpwent()
  61. {
  62.     _pw_count = 0
  63. }
  64.